package gxnu.edu.cn.mapper;

import gxnu.edu.cn.entity.Cuser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CuserMapper {

    /**
     * 根据用户名查询用户
     * @param userName
     * @return
     */
    @Select("select * from cuser where userName = #{userrName}")
    public Cuser getByusername(String userName);

    @Select("select * from cuser where userID = #{userID} AND passWord =#{passWord}")
    Cuser getByUserIdAndPassWord(Integer userID, String passWord);

    /**
     * 插入新用户
     * @param newUser 新用户对象
     * @return 插入成功的记录数
     */
    @Insert("INSERT INTO cuser (passWord, userName, permissionRole, failedLoginNum, accountLocked) " +
            "VALUES (#{passWord}, #{userName}, #{permissionRole}, 0, 1)")
    int insert(Cuser newUser);

    /**
     * 查询所有用户
     * @return 用户列表
     */
    @Select("SELECT userName , groupName, permissionRole, email , failedLoginNum , accountLocked  FROM cuser")
    List<Cuser> findAllUsers();
}
